/**
 * Date Modified: $Date: 2009-08-28 10:39:55 +1000 (Fri, 28 Aug 2009) $
 * Version: $Revision: 129 $
 * 
 * Copyright 2008 The Australian National University (ANU)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package org.ands.rifcs.example;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;


import org.ands.rifcs.base.*;

import org.xml.sax.SAXException;

public class DiseaseGroup
{
	private static RIFCS rifcs = null;

    public static void main(String[] args) throws RIFCSException, FileNotFoundException, SAXException, ParserConfigurationException, IOException
    {
        RIFCSWrapper mw = new RIFCSWrapper();
        rifcs = mw.getRIFCSObject();
        
        //Disease Group
        // variables
        // key, 
        
        //Hashtable<String, String> diseaseGroups[] = new Hashtable[2];
        String diseaseGroups[][] = {
        		//MRI Images
       /*key*/ 		 { "http://bit.ly/dWzloh",
       /*namePart*/     "MRI Images", 
       /*url*/ 		    "http://bit.ly/dWzloh", 
       /*subject*/ 	    "Medical Imaging, MRI Images", 
       /*description*/  "Dataset on MRI Images",
       /*rel1*/ 		"http://bit.ly/e2viVx"  //MRI Images RMH
        			 },
        		//PET Scans
        			 {"http://bit.ly/dVEFOs",
        			  "PET Scans",
        			  "http://bit.ly/dVEFOs",
        			  "Medical Imaging, PET Scans",
        			  "Dataset on PET Scans",
        			  "http://bit.ly/fhoWZt"  //PETIMG PMCI
        			 },
        			 
        		//Breast Cancer (Lab Results)
        			 {"http://bit.ly/g1ySEV",
        			  "Breast Cancer (Lab Results)",
        			  "http://bit.ly/g1ySEV",
        			  "Lab Results, Breast Cancer",
        			  "Dataset on lab results of Breast cancer",
        			  "http://bit.ly/gq2CBK" //Biomarkers RMH
        			 },
        		
        			 
        	    //Colorectal Cancer (Lab Results)
        			 {"http://bit.ly/fTVfyS",
        			  "Colorectal Cancer (Lab results)",
        			  "http://bit.ly/fTVfyS",
        			  "Lab Results, Colorectal Cancer",
        			  "Dataset on lab results of Colorectal cancer",
        			  "http://bit.ly/fLFR3N" //BRAF LICR
        			 },
        			 
        		//Breast Cancer
        			 {"http://bit.ly/dH2YKK",
        			  "Breast Cancer",
        			  "http://bit.ly/dH2YKK",
        			  "Oncology, Breast Cancer",
        			  "Dataset on Breast cancer",
        			  "http://bit.ly/g8dLOx", //Accord v1 Breast RMH/WH
        			  "http://bit.ly/eVPP7c", //Breast cancer BH
        			  "http://bit.ly/g3cUDf" //Breast cancer SVHM
        			 },
        			 
        		
        		//Sarcoma	 
        			 {"http://bit.ly/i8JhxX",
        			  "Sarcoma",
        			  "http://bit.ly/i8JhxX",
        			  "Oncology, Sarcoma",
        			  "http://bit.ly/fRdPSt"  //Accord v2 Sarcoma PMCI
        			 },
        			 
        		//Pituitary Cancer
        			 {"http://bit.ly/fzqu81",
        			  "Pituitary Cancer",
        			  "http://bit.ly/fzqu81",
        			  "Oncology, Pituitary Cancer",
        			  "http://bit.ly/eEV9pz",  //Pituitary Tumours RAH
        			  "http://bit.ly/fhprfO"  //Pituitary Tumours RMH
        			 }
        		
        		};
        
       
     
        for (int i=0;i<diseaseGroups.length;i++){
        	//FIXME: could possibly move registry object out of the loop
        	//		 so that all the collections are under one registry object
        	RegistryObject r = rifcs.newRegistryObject();
        	
            Collection myCollec = r.newCollection();
            Name n1 = myCollec.newName();
            Location loc = myCollec.newLocation();
            Address add = loc.newAddress();
            Electronic elec = add.newElectronic();
          
            //variable
            r.setKey(diseaseGroups[i][0]);
            
            r.setGroup(diseaseGroups[i][3].split(",")[0]);
            r.setOriginatingSource("https://services.ands.org.au/sandbox/orca");
            myCollec.setType("BioGrid");
            
        	//r.setKey("http://www.biogrid.org.au/wps/wcm/connect/4112c8004eda2cb1b5a1b534012b7aaf/DIABETES_AUSTIN.pdf?MOD=AJPERES  ");
        
        
        	//variable
            n1.addNamePart(diseaseGroups[i][1], "title");
        	//n1.addNamePart("Diabetes", "title");
        	myCollec.addName(n1);
    
        	elec.setType("url");
        	elec.setValue(diseaseGroups[i][2]);
        	//elec.setValue("http://bit.ly/ezUHOT");
        	add.addElectronic(elec);
        	loc.addAddress(add);
        	myCollec.addLocation(loc);
        
        
        	//variable
        	RelatedObject relObj = myCollec.newRelatedObject();
            relObj.setKey("www.biogrid.gov.au");
            relObj.addRelation("isLocatedIn", null, null, null);
            myCollec.addRelatedObject(relObj);
            
        	int size = diseaseGroups[i].length;
        	int relations = size - 5;
        	int j=1;
        	while(j<=relations){
        		RelatedObject relObj2 = myCollec.newRelatedObject();
        		if(diseaseGroups[i][4+j]==null){
        			
        			break;
        		}
        		relObj2.setKey(diseaseGroups[i][4+j]);
            	relObj2.addRelation("describes", null, null, null);
            	myCollec.addRelatedObject(relObj2);
            	j++;
        	}
      
        
        	//variable
        	myCollec.addSubject(diseaseGroups[i][3], "local", null);
        	//myCollec.addSubject("Endocrinology, Diabetes", "local", null);
        	//variable
        	myCollec.addDescription(diseaseGroups[i][4], "brief", null);
        	//myCollec.addDescription("Datasets on Diabetes", "brief", null);
        
        
        	r.addCollection(myCollec);
        	rifcs.addRegistryObject(r);
        
        	
        	
        }	
        mw.validate();

    	FileOutputStream outputFile=null;
    	try{
    		outputFile = new FileOutputStream("diseaseGroup2.xml");
    	}
    	catch(IOException e1){
    		System.out.println("Error writing to biogrid.xml");
    	}
    	mw.write(outputFile);
    	System.out.println("Successfully written to XML file.");
        	
    }
}